package com.chaintor.demo.math;

/**
 * 约束条件类
 */
public class Constraints {
    public double lower = 0.0;
    public double upper = 0.0;
    public boolean isConstrained = true;

    /**
     * 检查是否满足约束
     * @param candidate
     * @return
     */
    public boolean check(double candidate){
        if (isConstrained){
            if (candidate <= upper && candidate >= lower){
                return true;
            }else {
                return false;
            }
        }else {
            return true;
        }
    }

    public Constraints(double lower,double upper,boolean isConstrained){
        this.lower = lower;
        this.upper = upper;
        this.isConstrained = isConstrained;
    }

    public Constraints(double lower,double upper){
        this(lower,upper,true);
    }

}
